<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    let reg = /{{\s*([a-zA-Z]+)\s*}}/
    let str = '我是{{ name }}, 今年{{age}}, {{test}}'
    let arr

    let data = {
      name: '张三',
      age: 18,
      test: '测试'
    }

    while( arr = reg.exec(str) ) {  
      str = str.replace(arr[0], data[arr[1]])
    }

    console.log( str )
  </script>
</body>
</html>